home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pas_0593.zip / MOUSEINT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  4KB  |  118 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 233 of 288                                                               
  3. From : Trisdaresa Sumarjoso                1:272/38.0           28 May 93  06:18 
  4. To   : David Todd                                                                
  5. Subj : Tsr's                                                                  
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  -=> Quoting David Todd to All <=-
  8.  
  9.  DT> 
  10.  DT> Help! I'm having troubles making a TSR which involves a mouse. What I
  11.  DT> wanted  to do was make the TSR pop up when a mouse button was pressed.
  12.  DT> But I think  it screws up when I get the interrupt vector of the
  13.  DT> mouse, and later in the TSR I call Int 33h to read from the mouse. Can
  14.  DT> anybody help me out here with a simple example, which would make a
  15.  DT> sound if a mouse button is pressed? Thanks in advance...
  16.  
  17. Hello David...
  18.  
  19.         I've attached my little code to give some example about  how to
  20.         use Int 33h SubFunction 18h (which install
  21.         user-alternate-Subroutine).
  22.         Here is the stuff:}
  23.  
  24. Program TestMouseInt;
  25.  
  26. Uses
  27.     Dos, Crt;
  28.  
  29. Type
  30.     ProcType            = Procedure;
  31.  
  32. Var
  33.    Regs         : Registers;
  34.  
  35. Function CheckMouse(Var ButtonNumber: Byte): Boolean;
  36. Begin
  37.      Regs.AX := $00;
  38.      Intr($33, Regs);
  39.      ButtonNumber := Regs.BX;           { Total # of Button on the mouse }
  40.      CheckMouse := (Regs.AX <> 0);       { True if mouse is installed }
  41. End;
  42.  
  43. Procedure ShowMouse;
  44. Begin
  45.      Regs.AX := $01;
  46.      Intr($33, Regs);
  47. End;
  48.  
  49. Procedure HideMouse;
  50. Begin
  51.      Regs.AX := $02;
  52.      Intr($33, Regs);
  53. End;
  54.  
  55. {$F+}
  56. Procedure DoSound;
  57. Begin
  58.      Sound(220);
  59.      Delay(200);
  60.      NoSound;
  61. End;
  62. {$F-}
  63.  
  64. Function SetAltProc( AltProc: ProcType;
  65.                      CondMask: Word): Integer;
  66. Begin
  67.      Regs.AX := $18;            { SubFunction $18, Install user proc }
  68.  
  69.      {
  70.         The SubFunction $18 is prefered as it's offering a wider range
  71.         of condition than SubFunction $0C.
  72.      }
  73.  
  74.      Regs.CX := CondMask;       { Condition to be met }
  75.      Regs.DX := Ofs(AltProc);   { Offset of the alternate proc }
  76.      Regs.ES := Seg(AltProc);   { Segment of the alternate proc }
  77.      Intr($33, Regs);
  78.      SetAltProc := Regs.AX;
  79. End;
  80.  
  81. Var
  82.    ButtonNumber : Byte;
  83.    Result       : Integer;
  84.  
  85. Begin
  86.      If CheckMouse(ButtonNumber) Then
  87.      Begin
  88.           ClrScr;
  89.           ShowMouse;
  90.           Result := SetAltProc(DoSound, 34);    { 34 = Shift + Left
  91.                                                   button }
  92.           If (Result <> -1) Then
  93.              Repeat
  94.                    WriteLn('Press Shift+left mouse button...');
  95.                    WriteLn('Press <ENTER> to exit.');
  96.              Until (ReadKey = #13)
  97.           Else
  98.               WriteLn('Unable to install procedure...');
  99.      End
  100.      Else
  101.          WriteLn('Mouse is unavailable...');
  102. End.
  103.  
  104.         The reason I'm using SubFunction 18h here is because with this
  105.         SubFunction, you're allowed to used combination of keyboard-keys
  106.         (Shift, Ctrl, and Alt) with any mouse button (unfortunately, it
  107.         will ONLY work with this combo).
  108.         Another reason is with SubFunction 18h, you might be able to
  109.         avoid calling Int 33h directly (depending upon what info you
  110.         need). Since you're writing a TSR it might be better to use this
  111.         method since the driver will pass you some info on the mouse
  112.         (Such as AX --> Condition mask.
  113.                  BX --> Button state.
  114.                  CX --> Horizontal cursor coor.
  115.                  DX --> Vertical cursor coor.
  116.                  SI --> Horizontal mickeys.
  117.                  DI --> Vertical mickeys.)
  118.